import React from 'react';
import { Statistic as AntdStatistic } from 'antd';
import type { StatisticProps as AntdStatisticProps } from 'antd';
import { createStyles } from 'antd-style';

export interface StatisticProps extends AntdStatisticProps {
  /**
   * @description 自定义样式类名
   */
  customClassName?: string;
}

const useStyles = createStyles(({ token, css }) => ({
  statistic: css`
    .ant-statistic-content {
      color: ${token.colorText};
    }
  `,
}));

const StatisticComponent: React.FC<StatisticProps> = ({ customClassName, className, ...restProps }) => {
  const { styles, cx } = useStyles();
  
  const statisticClassName = cx(
    className,
    customClassName,
    styles.statistic
  );

  return <AntdStatistic className={statisticClassName} {...restProps} />;
};

// 创建复合组件
type StatisticType = typeof StatisticComponent & {
  Countdown: typeof AntdStatistic.Countdown;
  Timer: typeof AntdStatistic.Countdown;
};

const Statistic = StatisticComponent as StatisticType;

// 为 Timer 组件添加 type 属性支持
const TimerComponent = React.forwardRef<any, any>((props, _ref) => {
  const { type, ...restProps } = props;
  return <AntdStatistic.Countdown {...restProps} />;
});

// 导出子组件
Statistic.Countdown = AntdStatistic.Countdown;
Statistic.Timer = TimerComponent; // Timer with type support

export { Statistic };
export default Statistic;

